/*
* 包含 n 个操作 mongodb数据库集合的model的模块
* */
const mongoose = require('mongoose')

// 得到对应特定集合的 Model: UserModel
const userSchema = mongoose.Schema({
  // 用户名
  'username': { type: String },
  // 密码
  'password': { type: String },
  // 手机号
  'phone': { type: String }
})
UserModel = mongoose.model('user', userSchema)

// 得到对应特定集合的 Model: GoodsSchema
const goodsSchema = mongoose.Schema({
  'title': { type: String },
  "price": { type: Number },
  "pics": { type: Array },
  "images": { type: Array },
  "count": { type: Number },
  'inventory_count': { type: Number },
  "createTime": {
    type: Date,
    default: Date.now()
  }
})
GoodsSchema = mongoose.model('goods', goodsSchema)

// 得到对应特定集合的 Model: GoodsSchema
const shopCartsSchema = mongoose.Schema({
  "userId": { type: String },
  "title": { type: String },
  "price": { type: Number },
  'count': { type: Number },
  "pic": { type: String }
})
ShopCartsSchema = mongoose.model('shopCarts', shopCartsSchema)

// 向外暴露
module.exports = {
  getModel (name) {
    return mongoose.model(name)
  }
}


